import VuiElement from '../base/element';
import { createInput, createLabel } from '../dom';

export default class VuiInput extends VuiElement {
  constructor(label, config) {
    super();
    const defaultConfig = {
      id: '',
      className: '',
      value: '',
      name: '',
      type: 'text',
      readOnly: '',
      autocomplete: 'off'
    };
    this.labelConfig = {
      id: config.id + 'Label',
      className: '',
      innerText: label,
      htmlFor: config.id
    };
    this._config = Object.assign(defaultConfig, config);
  }

  initUI() {
    this.container = this.createDiv();
    const label = createLabel(this.labelConfig);
    this.input = createInput(this._config);
    this.append([label, this.input]);
  }

  getValue() {
    return this.input.value;
  }

  setValue(value) {
    this.input.value = value;
  }
}
